public class WordFrequencyCount{
         
         public static void solution(String fileName,int n){ 
               File  wf = new File(fileName);
               long wordLength = wf.length();
               //创建线程池
               ExecutorService pool  = new ThreadPoolExecutor(2,n,2L,TimeNuit.SECONDS,new LinkedBlockingQueue<>(3),new ThreadPoolExecutor.AbortPolicy());           
               List<Future> list = new ArrayList<Future>();
               for(int i=0;i<n;i++){
                                    
                        Callable c = new MyCallable(fileName,i/n,(i+1)/n*wordLength);
                        //创建任务并获取返回对象
                        Future f = pool.submit(c);
                        list.add(f);
               }
               //关闭线程池
               pool.shutdown();
               
               //处理list结果
               TreeMap tm = new TreeMap();
               for(Future f:list){
                    ConcurrentHashMap cm = (ConcurrentHashMap)f.get();
                    //不同线程处理的结果进行整合
                    tm.putAll(cm);
                            
               }

               //打印输出
               Set<Map.Entry<String,Integer>> entrySet = tm.entrySet();//map的一个个元素的集合
               List<Map.Entry<String,Integer>> entryList = new ArrayList<Map.Entry<String,Integer>>(entrySet);
               //比较
               Collections.sort(entryList,new Comparator<Map.Entry<String,Integer>>(){     
                      //降序排序
                      public int compare(Map.Entry<String,Integer> o1,Map.Entry<String,Integer> o2){                
                            return o2.getValue().compareTo(o1.getValue());
                                                                                                       
                      }                  
                                                        
               });
                 
               //打印
               for(int i=0;i<10;i++){         
                     Map.Entry<String,Integer> item = entryList.remove(i);                       
                    Ssytem.out.println(item.getKey()+":"+item.getValue());
               }          
                                  
        }
}

class MyCallable implements Callable{ 
    private FileChannel fc;  //文件通道   
    private FileLock fl;//文件锁
    private MappedByteBuffer mb;//内存映射文件
    private ConcurrentHashMap<> hm;
    //获取文件内容   
    //构造方法
    public  MyCallable(String file,int start,int end){  
        try{
         //得到文件的通道
         fc  = new RandomAccessFile(file,"rw").getChannel();           
         //锁住文件当前片段
         fl  = fc.lock(start,end,false);        
         //当前片段建立内存映射       
         mb = fc.map(,start,end); 
         hm = new ConcurrentHashMap<String,Integer>();
        }catch(Exception e){ 
                         
                e.printStackTrace();                 

        }
        
        }        
                
        @Override
        public Object call() throws Exception{
                         
             // 文件内容
              String str = ChartSet.forName("UTF-8").decode(mb).toString();
              // StringTokenizer              
              StringTokenizer token = new StringTokenizer(str);
              String word;
              while(token.hasMoreTokens()){
        	    word = token.next();

                if(hm.containsKey(word)){ 
                                         
                     hm.put(word,(Integer)hm.get(word)+1);                                    

                }else{
                    hm.put(word,1);                     
                                                         
                 }
              }                        
              try{
                  //释放锁                 
                   fl.release();                            
              }catch(Exception e){ 
                   e.printStackTrace();    

              }                           
              return  hm;                                                
                                                                           
        }
                          

}